// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import 'lib-flexible/flexible'
import Vant from 'vant';
import store from './store'
//添加公共接口配置
import Public from './api/index';
import filters from './filter/filters'


Vue.use(Vant)

Vue.prototype.Public = Public
Vue.config.productionTip = false

Object.keys(filters).forEach(key => {
  Vue.filter(key,filters[key])
})

//判断是否登录
router.beforeEach((to, from, next) => {
 // console.log(to)
  // to: Route: 即将要进入的目标 路由对象
  // from: Route: 当前导航正要离开的路由
  // next: Function: 一定要调用该方法来 resolve 这个钩子。执行效果依赖 next 方法的调用参数。
  　　let isLogin = sessionStorage.getItem('userInfo')&&JSON.parse(sessionStorage.getItem('userInfo')).token || '' // 是否登录
      console.log(isLogin)
  // 未登录状态；当路由到route指定页时，跳转至login
  　　if (!isLogin && to.name !='login') {
          next('/login')
　　　　}else{
  　　    next();
      }
     
});
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
